package org.jeecg.modules.xindian.reconciliation.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.xindian.reconciliation.entity.ChannelSettlementInfo;
import org.jeecg.modules.xindian.reconciliation.service.IChannelSettlementInfoService;
import org.jeecg.modules.xindian.reconciliation.service.IInsuranceSettlementConfigService;
import org.jeecg.modules.xindian.reconciliation.service.IInsuranceSettlementInfoService;
import org.jeecg.modules.xindian.reconciliation.service.ISalesmanSettlementInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(tags="测试模块")
@RestController
@RequestMapping("/reconciliation/test")
@Slf4j
public class TestController {
    @Autowired
    private IChannelSettlementInfoService channelSettlementInfoService;
    @Autowired
    private ISalesmanSettlementInfoService salesmanSettlementInfoService;
    @Autowired
    private IInsuranceSettlementInfoService insuranceSettlementInfoService;

    @Autowired
    private IInsuranceSettlementConfigService insuranceSettlementConfigService;

    /**
     * 账单周期记录
     *
     * @return
     */
    //@AutoLog(value = "杭州银行资金流水-分页列表查询")
    @ApiOperation(value = "账单周期记录", notes = "账单周期记录")
    @PostMapping(value = "/synchronizeMonth")
    public Result<IPage<ChannelSettlementInfo>> synchronizeMonth() {
//        Date lastMounth = DateUtil.parseDate("2024-05-30");
        Date lastMounth = DateUtil.offsetMonth(new Date(), -1);
        Date lastTwoMounth = DateUtil.offsetMonth(new Date(), -2);
        Date lastTreeMounth = DateUtil.offsetMonth(new Date(), -3);
        insuranceSettlementInfoService.synchronizeMonth(lastTwoMounth);
        insuranceSettlementInfoService.synchronizeMonth(lastMounth);
        insuranceSettlementInfoService.synchronizeMonth(lastTreeMounth);
        salesmanSettlementInfoService.synchronizeMouth(lastTwoMounth);
        salesmanSettlementInfoService.synchronizeMouth(lastMounth);
        salesmanSettlementInfoService.synchronizeMouth(lastTreeMounth);
        channelSettlementInfoService.synchronizeOneMonth(lastTwoMounth);
        channelSettlementInfoService.synchronizeOneMonth(lastMounth);
        channelSettlementInfoService.synchronizeOneMonth(lastTreeMounth);
        return Result.ok();
    }


    /**
     * 账单周期记录
     *
     * @return
     */
    @PostMapping(value = "/reBuildPlatformCode")
    public Result<IPage<ChannelSettlementInfo>> reBuildPlatformCode() {
        insuranceSettlementConfigService.reBuildPlatformCode();
        return Result.ok();
    }

}
